﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ProjScan.Submodules.Scene_Check;
using ProjScan.Tools;
using UnityEngine;

namespace ProjScan.ScanRule.SceneCheck
{
	// Token: 0x020001A7 RID: 423
	internal abstract class SceneGlobalRule : GlobalRule
	{
		// Token: 0x1700034F RID: 847
		// (get) Token: 0x06000E4E RID: 3662 RVA: 0x00041468 File Offset: 0x0003F668
		public override string DetailOutputPath
		{
			get
			{
				string str = "ErrorScene";
				bool flag = this.SceneId != null;
				if (flag)
				{
					str = Path.GetFileNameWithoutExtension(ScenesMapData.Instance.GetScenePathByIndex(base.SceneId.Value));
				}
				return Path.Combine(ToolsHelper.GetFailDetailPath(), this.RuleKey + "-" + str + ".csv");
			}
		}

		// Token: 0x06000E4F RID: 3663 RVA: 0x000414D4 File Offset: 0x0003F6D4
		public override bool HasFailedInfo()
		{
			return base.SceneId != null;
		}

		// Token: 0x06000E50 RID: 3664 RVA: 0x000414F4 File Offset: 0x0003F6F4
		public override string GetFailedInfo()
		{
			return (base.SceneId != null) ? this.GetScenePathByIndex(base.SceneId.Value) : string.Empty;
		}

		// Token: 0x06000E51 RID: 3665 RVA: 0x00041534 File Offset: 0x0003F734
		private string GetScenePathByIndex(int index)
		{
			int num = ScenesMapData.Instance.scenesList.Length;
			bool flag = index < 0 || index >= num;
			string result;
			if (flag)
			{
				Debug.LogError("Scene index out of range: " + index.ToString());
				result = string.Empty;
			}
			else
			{
				result = ScenesMapData.Instance.scenesList[index];
			}
			return result;
		}

		// Token: 0x06000E52 RID: 3666 RVA: 0x00041594 File Offset: 0x0003F794
		public void AnalysisFixData()
		{
			List<string> list = new List<string>();
			foreach (KeyValuePair<string, FailedAssetInfo> keyValuePair in this.failAssetInfos)
			{
				char[] separator = new char[]
				{
					'$'
				};
				string path = Enumerable.ToList<string>(keyValuePair.Key.Split(separator))[0];
				bool flag = Path.GetFullPath(path) == Path.GetFullPath(this.SceneName);
				if (flag)
				{
					this.failedAssetInfo = keyValuePair.Value;
				}
			}
		}

		// Token: 0x06000E53 RID: 3667 RVA: 0x00041644 File Offset: 0x0003F844
		public override void FixRule()
		{
			bool flag = this.failAssetInfos != null;
			if (flag)
			{
				this.AnalysisFixData();
				bool flag2 = this.failedAssetInfo != null;
				if (flag2)
				{
					bool flag3 = this.failedAssetInfo.ShouldBeFixed && !this.failedAssetInfo.IsFixed;
					if (flag3)
					{
						bool flag4 = this.InvokeFixer("This is Meant for Non - Path Fixer, Nothing will be Given");
						if (flag4)
						{
							this.failedAssetInfo.IsFixed = true;
							this.failedAssetInfo.ShouldBeFixed = false;
							FixLog.Instance.Log(this.fixerType, this.SceneName + "$hierachy");
						}
						else
						{
							this.failedAssetInfo.IsFixed = false;
						}
					}
					Dictionary<string, FailedAssetInfo> failAssetInfos = this.failAssetInfos;
					foreach (string text in Enumerable.ToList<string>(failAssetInfos.Keys))
					{
						string text2 = text.ToString();
						char[] separator = new char[]
						{
							'$'
						};
						string path = text2.Split(separator)[0];
						bool flag5 = Path.GetFullPath(path) == Path.GetFullPath(this.SceneName);
						if (flag5)
						{
							failAssetInfos[text2] = this.failedAssetInfo;
						}
					}
					this.failAssetInfos = failAssetInfos;
				}
			}
		}
	}
}
